package com.aso114.project.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.aso114.project.base.BaseApplication;


public class SpfUtil {
    private static final String DEFAULT_NAME = "net_answer";
    private static SpfUtil sInstance = null;
    private SharedPreferences spf = null;

    private SpfUtil() {
        spf = BaseApplication.getInstance().getSharedPreferences(DEFAULT_NAME, Context.MODE_PRIVATE);
    }

    public synchronized static SpfUtil getInstance() {
        if (sInstance == null) {
            sInstance = new SpfUtil();
        }
        return sInstance;
    }

    public void putString(String key, String value) {
        Editor editor = spf.edit();
        editor.putString(key, value);
        editor.commit();
    }

    public void putBoolean(String key, boolean value) {
        Editor editor = spf.edit();
        editor.putBoolean(key, value);
        editor.commit();
    }

    public String getString(String key, String defValue) {
        return spf.getString(key, defValue);
    }

    public boolean getBoolean(String key, boolean defValue) {
        return spf.getBoolean(key, defValue);
    }

    public void remove(String key) {
        Editor editor = spf.edit();
        editor.remove(key);
        editor.commit();
    }

    public void clear() {
        Editor editor = spf.edit();
        editor.clear();
        editor.commit();
    }
}
